//
//  JourneyTableViewCell.m
//  ITrip
//
//  Created by 1564335 on 15-5-31.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "JourneyTableViewCell.h"
#import <UIImageView+AFNetworking.h>
@implementation JourneyTableViewCell

- (void)dealloc
{
    [_entry_name release];
    [_tips release];
    [_image_url release];
    [_titleView release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)createCell
{
    self.titleView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleView];
    
    self.entry_name = [[UILabel alloc] init];
    [self.contentView addSubview:self.entry_name];
    [self.entry_name release];
    
    self.image_url = [[UIImageView alloc] init];
    [self.contentView addSubview:self.image_url];
    [self.image_url release];
    
    self.tips = [[UILabel alloc] init];
    [self.contentView addSubview:self.tips];
    [self.tips release];
    
    self.contentView.backgroundColor = [UIColor colorWithRed:231 / 255.0 green:237 / 255.0 blue:241 / 255.0 alpha:1];
}

- (void)setJourneyParser:(JourneyParserModel3 *)JourneyParser
{
    if (JourneyParser.entry_type != nil) {
        self.titleView .image = [UIImage imageNamed:@"iconfont-dingwei"];
        self.titleView.frame = CGRectMake(20, 20, 30, 30);
        self.titleView.backgroundColor = [UIColor clearColor];
//        self.titleView.layer.borderColor = [UIColor grayColor].CGColor;
//        self.titleView.layer.borderWidth = 1.5;
//        self.titleView.layer.cornerRadius = 20;
//        self.titleView.layer.masksToBounds = YES;
        self.entry_name.frame = CGRectMake(70, 30, 200, 25);
        self.entry_name.text = JourneyParser.entry_name;
    }
   
    if (JourneyParser.image_url != nil && ![JourneyParser.image_url isEqual:[NSNull null]]) {
        [self.image_url setImageWithURL:[NSURL URLWithString:JourneyParser.image_url] placeholderImage:[UIImage imageNamed:@"defaultPicture"]];
    }
    // 有title
    if (JourneyParser.entry_type != nil) {
        // 有图片
        if (JourneyParser.image_url != nil) {
            self.image_url.frame = CGRectMake(20, 70, self.frame.size.width - 40, 200);
            
            // 有字
            if (JourneyParser.tips != nil) {
                self.tips.frame = CGRectMake(20, self.image_url.frame.origin.y + self.image_url.frame.size.height + 20, self.frame.size.width - 40, 30);
                                             
                self.tips.font = [UIFont systemFontOfSize:15];
                self.tips.text = JourneyParser.tips;
                self.tips.numberOfLines = 1000;
                [self.tips sizeToFit];
                
            }
            
        } else {
            // 无图
            if (JourneyParser.tips != nil) {
                self.tips.frame = CGRectMake(20, 70, self.frame.size.width - 40, 30);
                
                self.tips.font = [UIFont systemFontOfSize:15];
                self.tips.text = JourneyParser.tips;
                self.tips.numberOfLines = 1000;
                [self.tips sizeToFit];
                
            }
            
        }
        
        // 无title
    } else { // 无title
        // 有图
        if (JourneyParser.image_url != nil) {
            self.image_url.frame = CGRectMake(20, 20, self.frame.size.width - 40, 200);
            
            if (JourneyParser.tips != nil) {
                
                self.tips.frame = CGRectMake(20, self.image_url.frame.origin.y + self.image_url.frame.size.height + 20, self.frame.size.width - 40, 30);
                self.tips.font = [UIFont systemFontOfSize:15];
                self.tips.text = JourneyParser.tips;
                self.tips.numberOfLines = 1000;
                [self.tips sizeToFit];
            }
            
        } else {
            // 无图
            if (JourneyParser.tips != nil) {
                
                self.tips.frame = CGRectMake(20, 20, self.frame.size.width - 40, 30);
                self.tips.font = [UIFont systemFontOfSize:15];
                self.tips.text = JourneyParser.tips;
                self.tips.numberOfLines = 1000;
                [self.tips sizeToFit];
            }
        }
    }
    
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
